<template>
  <div class="Page">
    <div
      id="lineOne"
      style="height: 300px;width: 100%"
    ></div>
    <div style="height: 20px;"></div>
    <div
      id="lineTwo"
      style="height: 300px;width: 100%"
    ></div>
    <div style="height: 20px;"></div>
  </div>
</template>
<script>
// 按需加载
const echarts = require('echarts')
// 引入折线图组件
require('echarts/lib/chart/line')
// 引入提示框和title组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
export default {
  name: 'Page',
  components: {},
  data () {
    return {
      lineOne: {
        title: {
          text: '折线图堆叠'
        },
        tooltip: {
          trigger: 'axis',
          backgroundColor: 'pink',
          borderWidth: 1,
          borderColor: 'red',
          padding: [10, 10, 10, 10],
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          },
          // formatter: function (params) {  // 鼠标经过的弹窗的内容
          //   console.log(params)
          //   return params
          // },
          textStyle: {
            fontSize: 14,
            color: '#000'
          }
        },
        legend: {
          data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        dataZoom: {
          type: 'inside'
        },
        toolbox: {
          feature: {
            saveAsImage: {
              show: true,
              name: '下载文件名（趋势图）',
              iconStyle: {
                borderColor: 'Blue'
              },
              emphasis: {
                iconStyle: {
                  borderColor: 'red'
                }
              }
            }
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: '邮件营销',
            type: 'line',
            stack: '总量',
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: '联盟广告',
            type: 'line',
            stack: '总量',
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: '视频广告',
            type: 'line',
            stack: '总量',
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: '直接访问',
            type: 'line',
            stack: '总量',
            data: [320, 332, 301, 334, 390, 330, 320]
          },
          {
            name: '搜索引擎',
            type: 'line',
            stack: '总量',
            data: [820, 932, 901, 934, 1290, 1330, 1320]
          }
        ]
      },
      lineTwo: {
        title: {
          text: '堆叠区域图'
        },
        tooltip: {
          trigger: 'axis'
        },
        color: ['#274C55', '#3E6972', '#67A1A8', '#AECBCE', '#999'],
        legend: {
          width: '80%',
          data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
        },
        dataZoom: {
          type: 'inside'
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '邮件营销',
            type: 'line',
            stack: '总量',
            areaStyle: {},
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: '联盟广告',
            type: 'line',
            stack: '总量',
            areaStyle: {},
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: '视频广告',
            type: 'line',
            stack: '总量',
            areaStyle: {},
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: '直接访问',
            type: 'line',
            stack: '总量',
            areaStyle: {},
            data: [320, 332, 301, 334, 390, 330, 320]
          },
          {
            name: '搜索引擎',
            type: 'line',
            stack: '总量',
            // label: {
            //   normal: {
            //     show: true,
            //     position: 'top'
            //   }
            // },
            areaStyle: {},
            data: [820, 932, 901, 934, 1290, 1330, 1320]
          }
        ]
      }
    }
  },
  created () { },
  mounted () {
    this.drawLine()
  },
  methods: {
    drawLine () {
      const myChartOne = echarts.init(document.getElementById('lineOne'))
      myChartOne.setOption(this.lineOne)

      const myChartTwo = echarts.init(document.getElementById('lineTwo'))
      myChartTwo.setOption(this.lineTwo)
    }
  }
}
</script>
<style scoped lang="less">
</style>
